#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>

bool is_Prime(int num) {
    if (num <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {

    std::unordered_map<std::string, int> Chisla_all = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3},
        {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7},
        {"eight", 8}, {"nine", 9}
    };


    std::string one_w, two_w, three_w;
    if (!(std::cin >> one_w) || Chisla_all.find(one_w) == Chisla_all.end()) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }
    if (!(std::cin >> two_w) || Chisla_all.find(two_w) == Chisla_all.end()) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }
    if (!(std::cin >> three_w) || Chisla_all.find(three_w) == Chisla_all.end()) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int num = Chisla_all[one_w] * 100 + Chisla_all[two_w] * 10 + Chisla_all[three_w];

    if (num < 100 || num > 999) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    if (is_Prime(num)) {
        int diff = 1;
        while (true) {
            if (is_Prime(num + diff)) {
                std::cout << num + diff << std::endl;
                break;
            }
            if (is_Prime(num - diff)) {
                std::cout << num - diff << std::endl;
                break;
            }
            diff++;
        }
    } else {
        int diff = 0;
        while (true) {
            if (is_Prime(num - diff)) {
                std::cout << num - diff << std::endl;
                break;
            }
            if (is_Prime(num + diff)) {
                std::cout << num + diff << std::endl;
                break;
            }
            diff++;
        }
    }

    return 0;
}
